package com.scalar.chiptrack.sales;

import java.util.Iterator;
import java.util.ArrayList;
import java.util.Date;
import com.scalar.chiptrack.utils.StringUtils;
import java.util.HashMap;
import com.scalar.ScalarException;
import com.scalar.chiptrack.utils.ConfigManager;
import com.scalar.chiptrack.utils.Mailer;
import com.scalar.chiptrack.sales.dao.SalesOrderDAO;
import com.scalar.chiptrack.sales.dao.EndUserDAO;
import com.scalar.chiptrack.commons.Address;
import org.apache.struts.util.MessageResources;
import com.scalar.chiptrack.commons.Labels;
import com.scalar.chiptrack.commons.Constants;

public class SalesOrder
{

    private static final String SALES_ORDER_URI_1   = "/approveOrder.do?frmMail=1&salesOrderId=";
    private static final String SALES_ORDER_URI_2   = "/order.do?frmMail=1&salesOrderId=";
    private static final String USER_PROFILE_URI    = "userProfile.do";

    private int salesOrderId            = -1;
    private int customerId              = -1;
    private int billingAddressId        = -1;
    private int shippingAddressId       = -1;
    private int alaramId                = -1;
    private int salesOrderReleaseNumber = 0;//This is used for saving the release number of the sales order from
    private int approvedCount           = 0;
    private int odmId                   = -1;
    private int shippingInstructionsId  = -1;
    private int freightInstructionsId   = -1;
    private int quotationId             = -1;
    private int endCustomerId           = -1;


    private float subTotal              = 0.0f;
    private float salesTax              = 0.0f;
    private float frieght               = 0.0f;
    private float misc                  = 0.0f;
    private float orderTotal            = 0.0f;
    private float salesTaxValue         = 0f;

    double subTotalAsDouble             = 0.0;
    double salesTaxAsDouble             = 0.0;
    double frieghtAsDouble              = 0.0;
    double miscAsDouble                 = 0.0;
    double orderTotalAsDouble           = 0.0;
    private double finalSubTotal        = 0.0;/* To calculate Subtotal,SalesTax and Order Total for quantity to be Shipped */
    private double finalSalesTax        = 0.0;
    private double finalOrderTotal      = 0.0;

    private String salesOrderNo         = null;
    private String customerName         = null;
    private String customerPo           = null;
    private String contactPerson        = null;
    private String salesPerson          = null;
    private String phoneNumber          = null;
    private String faxNumber            = null;
    private String email                = null;
    private String endUser              = null;
    private String shippingMethod       = null;
    private String shippingAccount      = null;
    private String billingAddress       = null;
    private String shippingAddress      = null;
    private String comments             = null;
    private String shippingInstructions = null;
    private String status               = null;
    private String enteredById          = null;
    private String enteredByName        = null;
    private String enteredDate          = null;
    private String shippingMethodName   = null;
    private String reason               = null;
    private String salesOrderDate       = null;
    private String action               = null;
    private String status_temp          = null;
    private String cellNumber           = null;
    private String billingContactPerson = null;
    private String shippingContactPerson= null;
    private String customerNumber       = "";
    private String epicoreShippingAddressCode = "";
    private String requiredShipDate     = "1/1/1900";
    private String scheduleShipDate     = "1/1/1900";
    private String epicoreSalesOrderStatus = "";
    private String address              = null;
    private String salesRep             = null;
    private String poRev                = null;
    private String poDate               = null;
    private String odm                  = null;
    private String freightInstructions  = null;
    private String letterOfCreditNo     = null;
    private String lcIssuingBank        = null;
    private String oracleShippingAddressId  = null;
    private String oracleBillingAddressId   = null;
    private String orderType            = null;
    private String salesTaxType         = null;
    private String miscName             = "Misc";
    private String newShippingMethod    = null;
    public  String clientName           = null;
    private String regionalRep          = null;
    private String shippingTerms        = null;
    private String deliveryTerms        = "EXW";
    private String newShippingTerms     = null;
    private String billingAddressAsHTML = "";
    private String shippingAddressAsHTML= "";
    private String clientAddress        = null;
    private String clientAddressAsHTML  = "";
    private String quotationNo;
    private String endCustomer = null;

    private boolean isCancel            = false;
    private boolean isSample            = false;
    private boolean isPending           = false;
    private boolean isShipped           = false;
    private boolean sales_order_status  = false;
    private boolean epicoreHold         = false;
    private boolean isEndCustomerShipAddress = false;

    private Date bookingDate            = null;

    private ArrayList shippingMethods   = null;
    private ArrayList shippingAddresses = null;
    private ArrayList billingAddresses = null;
    private ArrayList contactPersons    = null;
    private ArrayList contactPersonsForBillingAddress = null;
    private ArrayList contactPersonsForShippingAddress = null;
    private ArrayList salesPersons      = null;
    private ArrayList salesReps         = null;
    private ArrayList odmList           = null;
    private ArrayList previousLineItems = null;
    private ArrayList mfgParts          = null;
    private ArrayList allDeliveryTerms  = null;
    private ArrayList allShippingTerms  = null;
    private ArrayList endCustomerList   = null;
    private ArrayList transferredLineItems = null;

    private HashMap billingAddressMap           = null;
    private HashMap shippingAddressMap          = null;
    private HashMap customerContactPersonMap    = null;
    private HashMap mfgPartsWithComments        = null;
    private HashMap mfgPartsWithBaseOrderQty    = null;
    private HashMap mfgPartsWithCustomerPartNos = null;
    private HashMap mfgPartsWithLabelNumbers    = null;

    private Address billingAddressAsObject      = new Address();
    private Address shippingAddressAsObject     = null;
    private Address clientAddressAsObject       = new Address();
    private boolean isConsignee;
    private String isConsignmentSales; //0 - true, 1 - false, null need to select in JSP
    private String newEndUserName;
    private String newEndCustomerName;
    private String userField1;
    private String userField2;

    public SalesOrder() { }

    public SalesOrder( int salesOrderId, int customerId, String customerPo, String contactPerson,
                       String salesPerson, String shippingMethod, String shippingAccount,
                       int billingAddressId, int shippingAddressId, String comments,
                       String shippingInstructions, String endUser, java.util.Date bookingDate, boolean isSample )
    {

        this.salesOrderId = salesOrderId;
        this.customerId = customerId;
        this.customerPo = customerPo;
        this.contactPerson = contactPerson;
        this.salesPerson = salesPerson;
        this.shippingMethod = shippingMethod;
        this.shippingAccount = shippingAccount;
        this.billingAddressId = billingAddressId;
        this.shippingAddressId = shippingAddressId;
        this.comments = comments;
        this.shippingInstructions = shippingInstructions;
        this.endUser = endUser;
        this.bookingDate = bookingDate;
        this.salesOrderDate = StringUtils.formatDateToString( bookingDate );
        this.isSample = isSample;
    }

    public int getSalesOrderId()
    {
        return salesOrderId;
    }

    public void setSalesOrderId( int salesOrderId )
    {
        this.salesOrderId = salesOrderId;
    }

    public String getSalesOrderNo()
    {
        return salesOrderNo;
    }

    public void setSalesOrderNo( String salesOrderNo )
    {
        this.salesOrderNo = salesOrderNo;
    }

    public int getCustomerId()
    {
        return customerId;
    }

    public void setCustomerId( int customerId )
    {
        this.customerId = customerId;
    }

    public String getCustomerName()
    {
        return customerName;
    }

    public void setCustomerName( String customerName )
    {
        this.customerName = customerName;
    }

    public String getCustomerPO()
    {
        return customerPo;
    }

    public void setCustomerPO( String customerPo )
    {
        this.customerPo = customerPo;
    }

    public String getContactPerson()
    {
        return contactPerson;
    }

    public void setContactPerson( String contactPerson )
    {
        this.contactPerson = contactPerson;
    }

    public String getCellNumber()
    {
        return cellNumber;
    }

    public void setCellNumber( String cellNumber )
    {
        this.cellNumber = cellNumber;
    }

    public String getSalesPerson()
    {
        if( salesPerson == null )
            salesPerson = " ";

         if( salesPerson != null ){
            salesPerson = salesPerson.trim() ;
        }
        return salesPerson;
    }

    public String getSalesRep()
    {
        if( salesRep == null )
            salesRep = " ";
        if( salesPerson != null ){
            salesPerson = salesPerson.trim() ;
        }
        return salesRep;
    }

    public String getAddress()
    {
        if( address == null )
            address = "";
        return address;
    }

    public void setAddress( String address )
    {
        this.address = address;
    }

    public void setSalesPerson( String salesPerson )
    {
        this.salesPerson = salesPerson;
    }

    public void setSalesRep( String salesRep )
    {
        this.salesRep = salesRep;
    }

    public String getPhoneNumber()
    {
        return phoneNumber;
    }

    public void setPhoneNumber( String phoneNumber )
    {
        this.phoneNumber = phoneNumber;
    }

    public String getFaxNumber()
    {
        return faxNumber;
    }

    public void setFaxNumber( String faxNumber )
    {
        this.faxNumber = faxNumber;
    }

    public String getEmail()
    {
        return email;
    }

    public void setEmail( String email )
    {
        this.email = email;
    }

    public String getEndUser()
    {
        if(  endUser != null && "null".equals( endUser.trim() ))
        {
             endUser = "";
        }
        return endUser;
    }

    public void setEndUser( String endUser )
    {
        this.endUser = endUser;
    }

    public String getShippingMethod()
    {
        String finalShippingMethod = "";
        if(  shippingMethod != null && "null".equals( shippingMethod.trim() ))
        {
             shippingMethod = "";
        }
        if( shippingMethod != null && shippingMethod.trim().length() == 0 )
        {
            finalShippingMethod = "";
        }
        else
        {
            finalShippingMethod = shippingMethod + "   #   " + shippingAccount;
        }

        return finalShippingMethod;
    }

    public void setShippingMethod( String shippingMethod )
    {
        this.shippingMethod = shippingMethod;
    }

    public String getShippingAccount()
    {
        return shippingAccount;
    }

    public void setShippingAccount( String shippingAccount )
    {
        this.shippingAccount = shippingAccount;
    }

    public ArrayList getShippingMethods()
    {
        return shippingMethods;
    }

    public void setShippingMethods( ArrayList shippingMethods )
    {
        this.shippingMethods = shippingMethods;
    }

    public ArrayList getContactPersons()
    {
        return contactPersons;
    }

    public void setContactPersons( ArrayList contactPersons )
    {
        this.contactPersons = contactPersons;
    }

    public ArrayList getContactPersonsForBillingAddress()
    {
        return contactPersonsForBillingAddress;
    }

    public void setContactPersonsForBillingAddress( ArrayList contactPersonsForBillingAddress )
    {
        this.contactPersonsForBillingAddress = contactPersonsForBillingAddress;
    }

    public ArrayList getContactPersonsForShippingAddress()
    {
        return contactPersonsForShippingAddress;
    }

    public void setContactPersonsForShippingAddress( ArrayList contactPersonsForShippingAddress )
    {
        this.contactPersonsForShippingAddress = contactPersonsForShippingAddress;
    }

    public String getBillingContactPerson()
    {
        return billingContactPerson;
    }

    public void setBillingContactPerson( String billingContactPerson )
    {
        this.billingContactPerson = billingContactPerson;
    }

    public String getShippingContactPerson()
    {
        return shippingContactPerson;
    }

    public void setShippingContactPerson( String shippingContactPerson )
    {
        this.shippingContactPerson = shippingContactPerson;
    }

    public ArrayList getShippingAddresses()
    {
        return shippingAddresses;
    }

    public void setShippingAddresses( ArrayList shippingAddresses )
    {
        this.shippingAddresses = shippingAddresses;
    }

    public int getBillingAddressId()
    {
        return billingAddressId;
    }

    public void setBillingAddressId( int billingAddressId )
    {
        this.billingAddressId = billingAddressId;
    }

    public String getBillingAddress()
    {
        return billingAddress;
    }

    public void setBillingAddress( String billingAddress )
    {
        this.billingAddress = billingAddress;
    }

    public int getShippingAddressId()
    {
        return shippingAddressId;
    }

    public void setShippingAddressId( int shippingAddressId )
    {
        this.shippingAddressId = shippingAddressId;
    }

    public String getShippingAddress()
    {
        return shippingAddress;
    }

    public void setShippingAddress( String shippingAddress )
    {
        this.shippingAddress = shippingAddress;
    }

    public String getComments()
    {
        return comments;
    }

    public void setComments( String comments )
    {
        this.comments = comments;
    }

    public String getShippingInstructions()
    {
        return shippingInstructions;
    }

    public void setShippingInstructions( String shippingInstructions )
    {
        this.shippingInstructions = shippingInstructions;
    }

    public boolean isCancel()
    {
        return isCancel;
    }

    public void setIsCancel( boolean isCancel )
    {
        this.isCancel = isCancel;
    }

    public String getStatus()
    {
        return status;
    }

    public void setStatus( String status )
    {
        this.status = status;
    }

    public boolean getIsSample()
    {
        return isSample;
    }

    public void setIsSample( boolean isSample )
    {
        this.isSample = isSample;
    }

    public boolean isShipped()
    {
        return isShipped;
    }

    public void setIsShipped( boolean isShipped )
    {
        this.isShipped = isShipped;
    }

    public boolean isPending()
    {
        return isPending;
    }

    public void setIsPending( boolean isPending )
    {
        this.isPending = isPending;
    }

    public int getAlaramId()
    {
        return alaramId;
    }

    public void setAlaramId( int alaramId )
    {
        this.alaramId = alaramId;
    }

    public String getBookingdateAsString()
    {
        return ( StringUtils.formatDateToString( bookingDate, null ) );
    }

    public java.util.Date getBookingDate()
    {
        return bookingDate;
    }

    public void setBookingDate( java.util.Date bookingDate )
    {
        this.bookingDate = bookingDate;
    }

    public String getEnteredById()
    {
        return enteredById;
    }

    public void setEnteredById( String enteredById )
    {
        this.enteredById = enteredById;
    }

    public String getEnteredByName()
    {
        return enteredByName;
    }

    public void setEnteredByName( String enteredByName )
    {
        this.enteredByName = enteredByName;
    }

    public String getShippingMethodName()
    {
        int index1 = 0;
        if( shippingMethodName != null )
        {
            if( "null".equals( shippingMethodName.trim() ))
            {
                 shippingMethodName = "";
            }
            index1 = shippingMethodName.indexOf( " # " );
            if( index1 != -1 && index1 != 0 )
            {
                shippingMethodName = shippingMethodName.substring( 0, index1 );
            }
        }


        return shippingMethodName;
    }

    public void setShippingMethodName( String shippingMethodName )
    {
        this.shippingMethodName = shippingMethodName;
    }

    public String getReason()
    {
        return reason;
    }

    public void setReason( String reason )
    {
        this.reason = reason;
    }

    private int changeNumber;

    public int getChangeNumber()
    {
        return changeNumber;
    }

    public void setChangeNumber( int changeNumber )
    {
        this.changeNumber = changeNumber;
    }


    public String getEnteredDate()
    {
        return this.enteredDate;
    }

    public void setEnteredDate( String date )
    {
        this.enteredDate = date;
    }


    public String getSalesOrderDate()
    {
        return salesOrderDate;
    }

    public void setSalesOrderDate( String salesOrderDate )
    {
        this.salesOrderDate = salesOrderDate;
    }

    public int getOdmId() {
            return odmId;
    }

    public void setOdmId(int odmId) {
        this.odmId = odmId;
    }

    public String getOdm() {
        return odm;
    }

    public void setOdm(String odm) {
        this.odm = odm;
    }

    public boolean getIsEndCustomerShipAddress() {
        return isEndCustomerShipAddress;
    }

    public void setIsEndCustomerShipAddress(boolean endCustomerShipAddress) {
        isEndCustomerShipAddress = endCustomerShipAddress;
    }

    public int getShippingInstructionsId() {
        return shippingInstructionsId;
    }

    public void setShippingInstructionsId(int shippingInstructionsId) {
        this.shippingInstructionsId = shippingInstructionsId;
    }

    public static String getHtmlView( int salesOrderId ) throws ScalarException
    {
        SalesOrder salesOrder = SalesOrderDAO.loadSalesOrder( salesOrderId + "" );
        return salesOrder.getHtmlView();
    }


    public String getHtmlView() throws ScalarException
    {
        SalesOrder salesOrder = this;
        ArrayList presentLineItems = SalesOrderDAO.loadOrderLineItemsByCustomerId( salesOrder.getSalesOrderId(), salesOrder.getCustomerId() );

        if( presentLineItems == null ) presentLineItems = new ArrayList();

        if( salesOrder.getEndUser().trim().equals( "" ) )
        {
            //Empty
        }
        else
        {
            int endUserId = EndUserDAO.getEndUserIdByName( salesOrder.getEndUser(), salesOrder.getCustomerId() );
            SalesOrderDAO.loadEndUserPartNumbersForLineItems( null, presentLineItems, endUserId );
        }
        boolean isClientAirgo = false;
        String endUserLabel = null;
        String poRevLabel = null;
        String poDateLabel = null;
        String representativeLabel = null;
        String deliveryTermsLabel = null;
        String endCustomerLabel = null;
        try
        {
            endCustomerLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.endCustomer" );
            if ( endCustomerLabel == null )
            {
                endCustomerLabel = Labels.DEFAULT_END_CUSTOMER_LABEL;
            }
        }
        catch ( NullPointerException e )
        {
            endCustomerLabel    = Labels.DEFAULT_END_CUSTOMER_LABEL;
        }
        try
        {
            endUserLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.endUser" );
            if ( endUserLabel == null )
            {
                endUserLabel = Labels.DEFAULT_END_USER_LABEL;
            }
        }
        catch ( NullPointerException e )
        {
            endUserLabel    = Labels.DEFAULT_END_USER_LABEL;
        }
        try
        {
            poRevLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.PoRevisionNumber" );
            if ( poRevLabel == null )
            {
                poRevLabel = Labels.DEFAULT_PO_REV;
            }
        }
        catch ( NullPointerException e )
        {
            poRevLabel = Labels.DEFAULT_PO_REV;
        }
        try
        {
            poDateLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.PoDate" );
            if ( poDateLabel == null )
            {
                poDateLabel = Labels.DEFAULT_PO_DATE;
            }
        }
        catch ( NullPointerException e )
        {
            poDateLabel = Labels.DEFAULT_PO_DATE;
        }
        try
        {
            representativeLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesRep.Name" );
            if ( representativeLabel == null )
            {
                representativeLabel = Labels.DEFAULT_REPRESENTATIVE;
            }
        }
        catch ( NullPointerException e )
        {
            representativeLabel = Labels.DEFAULT_REPRESENTATIVE;
        }
        try
        {
            deliveryTermsLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.DeliveryTerms" );
            if ( deliveryTermsLabel == null )
            {
                deliveryTermsLabel = Labels.DEFAULT_DELIVERY_TERMS_LABEL;
            }
        }
        catch ( NullPointerException e )
        {
            deliveryTermsLabel    = Labels.DEFAULT_DELIVERY_TERMS_LABEL;
        }
        if ( Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() ) ) {
            isClientAirgo = true;
        }
        String heading  = null;
        if ( salesOrder.getIsSample() )
        {
            heading = "Sample";
        }
        else
        {
            heading = "Sales";
        }
        StringBuffer htmlView = new StringBuffer();

        htmlView.append( "<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE><META http-equiv=Content-Type content='text/html; charset=windows-1252'>\n" );

        htmlView.append( "<style type=\"text/css\">" );
        htmlView.append( "#toc a{ font-family: Verdana;font-style : normal ;font-size : 7pt; font-weight :bold;}" );
        htmlView.append( "#toc p{font-family: Verdana;font-style : normal ;font-size : 7pt; font-weight :bold;text-align :center;color :#FFFFFF}" );
        htmlView.append( "#toc {border-style : solid;border-color :#000000 ;border-width :medium }" );
        htmlView.append( "</style></head>\n" );


        htmlView.append( "<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight='0' marginwidth='0'><br>\n" );

        htmlView.append( "<TABLE cellSpacing=0 cellPadding=0 width='100%' border=1 bgcolor='#FFFFFF' align='center' style='FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana'><tr><td>\n" );
        htmlView.append( "<table cellSpacing=0 cellPadding=3 width='100%' border=0 bgcolor='#FFFFFF' align='center' style='FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana'>\n" );
        htmlView.append( "<tr><td colspan='6' align='center'><br></td></tr>\n" );
        htmlView.append( "<tr><td colspan='6' bgcolor='#ccccff' valign='center' align='center'><SPAN style='FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana'><strong>"+heading+ " Order</strong></span></td></tr>\n" );

        htmlView.append( "<tr bgColor='#e6e6e6'><td width='21%'>Created By:</font></td>\n" );
        htmlView.append( "<td width='21%' class='bodytext'>" + ( ( salesOrder.getEnteredById() == null ) ? "" : salesOrder.getEnteredById() ) + "</td>\n" );
        htmlView.append( "<td width='3%'>&nbsp;</td><td width='21%'>Last Updated On:</font></td>\n" );
        htmlView.append( "<td width='21%' class='bodytext'>" + ( ( salesOrder.getEnteredDate() == null ) ? "" : salesOrder.getEnteredDate() ) + "</td>\n" );

        htmlView.append( "<td width='3%'>&nbsp;</td></tr><tr  bgColor='#e6e6e6'><td colspan='6' align='center'><br></td></tr>\n" );

        htmlView.append( "<tr  bgColor='#e6e6e6'><td width='21%'><font class='NArialL'>Sales Order No :</font></td>\n" );
        htmlView.append( "<td width='21%' class='bodytext'><b>" + salesOrder.getSalesOrderNo() + "</b></td>\n" );
        htmlView.append( "<td width='3%'>&nbsp;</td><td width='21%'>Customer Name :</font></td>" );
        htmlView.append( "<td width='21%' class='bodytext'>" + salesOrder.getCustomerName() + "</td><td></td>" );

        htmlView.append( "</tr><tr  bgColor='#e6e6e6'><td width='21%'>Customer PO No :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getCustomerPO() == null ) ? "" : salesOrder.getCustomerPO() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Contact Person :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getContactPerson() == null ) ? "" : salesOrder.getContactPerson() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>"+poRevLabel+ " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getPoRev() == null ) ? "" : salesOrder.getPoRev() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>"+poDateLabel+ " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getPoDate() == null ) ? "" : salesOrder.getPoDate() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );


        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Phone :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getPhoneNumber() == null ) ? "" : salesOrder.getPhoneNumber() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Cell No :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getCellNumber() == null ) ? "" : salesOrder.getCellNumber() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr  bgColor='#e6e6e6'><td width='21%'>Fax :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getFaxNumber() == null ) ? "" : salesOrder.getFaxNumber() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Email :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getEmail() == null ) ? "" : salesOrder.getEmail() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Sales Person :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getSalesPerson() == null ) ? "" : salesOrder.getSalesPerson() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>"+representativeLabel+ " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getSalesRep() == null ) ? "" : salesOrder.getSalesRep() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        String shippingMethodLabel = null;
        try
        {
            shippingMethodLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.ShippingMethod" );
            if ( shippingMethodLabel == null )
            {
                shippingMethodLabel = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
            }
        }
        catch ( NullPointerException e )
        {
            shippingMethodLabel    = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
        }
        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>"+shippingMethodLabel+" :</font></td>\n" );

        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( ( salesOrder.getShippingMethodName() == null ) || ( salesOrder.getShippingMethodName().trim().length() == 0 ) ) ? "" : salesOrder.getShippingMethodName() + "   #   " + salesOrder.getShippingAccount() ) + "</font></td><td width='3%'>&nbsp;</td><td></td><td></td><td></td>\n" );
        htmlView.append( "</tr><tr  bgColor='#e6e6e6'><td width='21%'>Pay Terms :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getShippingTerms() == null ) ? "" : salesOrder.getShippingTerms() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>"+deliveryTermsLabel+ ":</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getDeliveryTerms() == null ) ? "" : salesOrder.getDeliveryTerms() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Regional Rep :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getRegionalRep() == null ) ? "" : salesOrder.getRegionalRep() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Booking Date :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getSalesOrderDate() == null ) ? "" : salesOrder.getSalesOrderDate() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'> " + endUserLabel + " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getEndCustomer() == null ) ? "" : salesOrder.getEndCustomer() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'> " + endCustomerLabel + " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getOdm() == null ) ? "" : salesOrder.getOdm() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Billing Address :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getBillingAddress() == null ) ? "" : salesOrder.getBillingAddressAsHTML() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Shipping Address :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getShippingAddress() == null ) ? "" : salesOrder.getShippingAddressAsHTML() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Freight Instructions :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getFreightInstructions() == null ) ? "" : salesOrder.getFreightInstructions() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Shipping Instructions :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getShippingInstructions() == null ) ? "" : salesOrder.getShippingInstructions() ) + "</font></td><td width='3%'>&nbsp;</td></tr>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Comments :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getComments() == null ) ? "" : salesOrder.getComments() ) + "</font></td><td width='3%'>&nbsp;</td><td></td><td></td><td></td>\n" );
        htmlView.append( "</td></tr><tr><td colspan=6></td></tr><tr><td colspan=6><br></td></tr><tr><td colspan=6>\n" );

        if( presentLineItems.isEmpty() == false )
        {

            htmlView.append( "<TABLE style='FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana' borderColor='#ffffff' cellSpacing='1' cellPadding='3' width='100%' border=0><tr bgColor='#ccccff'>\n" );
            htmlView.append( "<td width='5%' align='center'>PO Line Item</td>\n" );
            htmlView.append( "<td width='5%' align='center'>Line Item</td>\n" );
            String mfgPartNumberLabel = MessageResources.getMessageResources( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage( "label.mfgPartNumber" );
            if( mfgPartNumberLabel == null )
            {
                mfgPartNumberLabel = Labels.DEFAULT_MFG_PART_NUMBER_LABEL;
            }

            htmlView.append( "<td width='7%' align='center'>" + mfgPartNumberLabel + "</td>\n" );
            String customerPartNumberLabel = MessageResources.getMessageResources( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage( "label.customerPartNumber" );
            if( customerPartNumberLabel == null )
            {
                customerPartNumberLabel = Labels.DEFAULT_CUSTOMER_PART_NUMBER_LABEL;
            }
            htmlView.append( "<td width='7%' align='center'>" + customerPartNumberLabel + "</td>\n" );
            String  labelNumberLabel = null;
            try
            {
                labelNumberLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.labelNumber" );
                if ( labelNumberLabel == null )
                {
                    labelNumberLabel = Labels.DEFAULT_LABEL_NUMBER_LABEL;
                }
            }
            catch ( NullPointerException e )
            {
                labelNumberLabel  = Labels.DEFAULT_LABEL_NUMBER_LABEL;
            }

            if ( isClientAirgo ) {
                htmlView.append( "<td width='7%' align='center'>" + labelNumberLabel + "</td>\n" );
            }
            htmlView.append( "<td width='8%' align='center'>Description</td>\n" );
            htmlView.append( "<td width='10%' align='center'>Taxable</td>\n" );
            htmlView.append( "<td width='10%' align='center'>Request Date</td>\n" );
            htmlView.append( "<td width='5%' align='center'>Quantity</td>\n" );
            htmlView.append( "<td width='10%' align='center'>Price </td>\n" );
            htmlView.append( "<td width='10%' align='center'>Amount</td>\n" );
            htmlView.append( "<td width='7%' align='center'>Sugg Ship Date</td>\n" );
            htmlView.append( "<td width='7%' align='center'>Scheduled Ship Date</td>\n" );
            htmlView.append( "<td width='6%' align='center'>Revised Ship Date</td>\n" );
            htmlView.append( "<td width='14%' align='center'>Holds<br>&nbsp;Mkg&nbsp;&nbsp;Fin&nbsp;&nbsp;Ops&nbsp;&nbsp;Sales&nbsp;</td>\n" );
            htmlView.append( "<td width='6%' align='center'>Expedite <br> Fee</td></tr>\n" );

            Iterator lineItems = presentLineItems.iterator();
            LineItem lineItem = null;
            String opHold = "";
            String finHold = "";
            String mkgHold = "";
            String salesHold = "";

            while( lineItems.hasNext() )
            {

                lineItem = ( LineItem ) lineItems.next();
                lineItem = SalesOrderDAO.loadHoldsForLineItem( lineItem );

                opHold = lineItem.getOperationsHold();
                if( ( opHold == null ) || ( opHold.trim().length() == 0 ) )
                {
                    opHold = "&nbsp;";
                }
                else if( "0".equalsIgnoreCase( opHold ) )
                {
                    opHold = "X";
                }

                finHold = lineItem.getFinanceHold();
                if( ( finHold == null ) || ( finHold.trim().length() == 0 ) )
                {
                    finHold = "&nbsp;";
                }
                else if( "0".equalsIgnoreCase( finHold ) )
                {
                    finHold = "X";
                }

                mkgHold = lineItem.getMarketingHold();
                if( ( mkgHold == null ) || ( mkgHold.trim().length() == 0 ) )
                {
                    mkgHold = "&nbsp;";
                }
                else if( "0".equalsIgnoreCase( mkgHold ) )
                {
                    mkgHold = "X";
                }

                salesHold = lineItem.getSalesHold();
                if( ( salesHold == null ) || ( salesHold.trim().length() == 0 ) )
                {
                    salesHold = "&nbsp;";
                }
                else if( "0".equalsIgnoreCase( salesHold ) )
                {
                    salesHold = "X";
                }

                htmlView.append( "<tr bgColor='#e6e6e6'><td width='5%' align='center'><font class='bodytext'>" + lineItem.getPoLineItemNo() + "</font></td>\n" );
                htmlView.append( "<td width='5%' align='center'><font class='bodytext'>" + lineItem.getLineItemNo() + "</font></td>\n" );
                htmlView.append( "<td width='7%' align='center' nowrap><font class='bodytext'>" + lineItem.getManufacturingPartNo() + "</font></td>\n" );
                htmlView.append( "<td width='7%' align='center' nowrap><font class='bodytext'>" + lineItem.getCustomerPartNo() + "</font></td>\n" );
                if ( isClientAirgo ) {
                    htmlView.append( "<td width='7%' align='center' nowrap><font class='bodytext'>" + ( lineItem.getLabelNumber() == null ? "" : lineItem.getLabelNumber() ) + "</font></td>\n" );
                }
                String desc = lineItem.getLineItemDescription();
                if( desc == null ) desc = "";
                htmlView.append( "<td width='8%' align='center' nowrap><font class='bodytext'>" + desc + "</font></td>\n" );
                htmlView.append( "<td width='10%' align='center' ><font class='bodytext'>" + ( ( lineItem.getIsTaxableAsString() == null ) ? "" : lineItem.getIsTaxableAsString() ) + "</font></td>\n" );
                htmlView.append( "<td width='10%' align='center' ><font class='bodytext'>" + ( ( lineItem.getRequestDate() == null ) ? "" : lineItem.getRequestDate() ) + "</font></td>\n" );
                htmlView.append( "<td width='5%' align='right' ><font class='bodytext'>" + StringUtils.formatUnits( lineItem.getQuantity() ) + "</font></td>\n" );

                htmlView.append( "<td  align='right' nowrap><font class='bodytext'>$" + StringUtils.formatAmountWithNoOfDecimals( lineItem.getUnitPriceAsDouble() ) + "</font></td>\n" );
                htmlView.append( "<td  align='right' nowrap><font class='bodytext'>$" + StringUtils.formatAmountWithNoOfDecimals( lineItem.getAmountAsDouble()) + "</font></td>\n" );

                htmlView.append( "<td width='7%' align='center' ><font class='bodytext'>" + ( ( lineItem.getSuggScheduleDate() == null ) ? "" : lineItem.getSuggScheduleDate() ) + "</font></td>\n" );
                htmlView.append( "<td width='7%' align='center' ><font class='bodytext'>" + ( ( lineItem.getScheduleDate() == null ) ? "" : lineItem.getScheduleDate() ) + "</font></td>\n" );
                htmlView.append( "<td width='6%' align='center' ><font class='bodytext'>" + ( ( lineItem.getRevisedDate() == null ) ? "" : lineItem.getRevisedDate() ) + "</font></td>\n" );
                htmlView.append( "<td width='14%' align='center' ><font class='bodytext'>&nbsp;[" + mkgHold.trim() + "]&nbsp;&nbsp;[" + finHold.trim() + "]&nbsp;&nbsp;[" + opHold.trim() + "]&nbsp;&nbsp;[" + salesHold.trim() + "]&nbsp;</font></td>\n" );
                boolean expediteValue = lineItem.getIsExpedite();
                String expediteFee = null;
                if( expediteValue == true )
                {
                    expediteFee = "Yes";
                }
                else
                {
                    expediteFee = "No";
                }

                htmlView.append( "<td width='6%' align='center'><font class='bodytext'>" + expediteFee + "</font></td></tr>\n" );

                status_temp = ( lineItem.getStatus() ).trim();
                if( ( "HOLD".equalsIgnoreCase( status_temp ) ) || ( "PENDING".equalsIgnoreCase( status_temp ) ) )
                {
                    sales_order_status = true;
                }
            }
            htmlView.append( "</table>" );
        }

        htmlView.append( "</td></tr><tr><td colspan='6' align='center'><br></td></tr>" );
        htmlView.append( "<tr><td colspan='6' align='center'><a href='http://" ).append( ConfigManager.getChipTracHost() ).append( "/" ).append( ConfigManager.getChipTracContext() );

        if( sales_order_status )
            htmlView.append( SALES_ORDER_URI_1 ).append( salesOrderId ).append("&isSample=").append((isSample?0:1)).append( "'><strong>Please click here to go to the sales order page</strong></a></td></tr>" );
        else
            htmlView.append( SALES_ORDER_URI_2 ).append( salesOrderId ).append("&isSample=").append((isSample?0:1)).append( "'><strong>Please click here to go to the sales order page</strong></a></td></tr>" );

        htmlView.append( "</table></td></tr></table>\n" );

        htmlView.append( "<br><br><br><br><table width='70%' border='0' style='FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana'>" );
        htmlView.append( "<tr><td>___________________________________________________________</td></tr>" );
        htmlView.append( "<tr><td>You are receiving this email because you have the access rights to</td></tr>" );
        htmlView.append( "<tr><td>approve a sales order from ChipTrac System. If you no longer wish you receive this email</td></tr>" );
        htmlView.append( "<tr><td>Please contact your system administrator.</td></tr></table>" );

        htmlView.append( "<br><br></BODY></HTML>\n" );

        return htmlView.toString();
    }

    public static String getHtmlViewWithChangeSummary( int salesOrderId, String changeSummary ) throws ScalarException
    {

        SalesOrder salesOrder = SalesOrderDAO.loadSalesOrder( salesOrderId + "" );
        return salesOrder.getHtmlViewWithChangeSummary( changeSummary );
    }

    public String getHtmlViewWithChangeSummary( String changeSummary ) throws ScalarException
    {
        return getHtmlViewWithChangeSummary( changeSummary, true );
    }
    public String getHtmlViewWithChangeSummary( String changeSummary, boolean showLinks ) throws ScalarException
    {
        SalesOrder salesOrder = this;
        ArrayList presentLineItems = SalesOrderDAO.loadOrderLineItemsByCustomerId( salesOrder.getSalesOrderId(), salesOrder.getCustomerId() );
        if( presentLineItems == null ) presentLineItems = new ArrayList();

        if( salesOrder.getEndUser().trim().equals( "" ) )
        {
            //salesOrder.setBillingAddressId(salesOrder.getBillingAddressId());
        }
        else
        {
            int endUserId = EndUserDAO.getEndUserIdByName( salesOrder.getEndUser(), salesOrder.getCustomerId() );
            SalesOrderDAO.loadEndUserPartNumbersForLineItems( null, presentLineItems, endUserId );
        }
        boolean isClientAirgo = false;
        String endUserLabel = null;
        String poRevLabel = null;
        String poDateLabel = null;
        String representativeLabel = null;
        String endCustomerLabel = null;
        try
        {
            endCustomerLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.endCustomer" );
            if ( endCustomerLabel == null )
            {
                endCustomerLabel = Labels.DEFAULT_END_CUSTOMER_LABEL;
            }
        }
        catch ( NullPointerException e )
        {
            endCustomerLabel    = Labels.DEFAULT_END_CUSTOMER_LABEL;
        }

        try
        {
            endUserLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.endUser" );
            if ( endUserLabel == null )
            {
                endUserLabel = Labels.DEFAULT_END_USER_LABEL;
            }
        }
        catch ( NullPointerException e )
        {
            endUserLabel    = Labels.DEFAULT_END_USER_LABEL;
        }

        try
        {
            poRevLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.PoRevisionNumber" );
            if ( poRevLabel == null )
            {
                poRevLabel = Labels.DEFAULT_PO_REV;
            }
        }
        catch ( NullPointerException e )
        {
            poRevLabel = Labels.DEFAULT_PO_REV;
        }
        try
        {
            poDateLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.PoDate" );
            if ( poDateLabel == null )
            {
                poDateLabel = Labels.DEFAULT_PO_DATE;
            }
        }
        catch ( NullPointerException e )
        {
            poDateLabel = Labels.DEFAULT_PO_DATE;
        }
        try
        {
            representativeLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesRep.Name" );
            if ( representativeLabel == null )
            {
                representativeLabel = Labels.DEFAULT_REPRESENTATIVE;
            }
        }
        catch ( NullPointerException e )
        {
            representativeLabel = Labels.DEFAULT_REPRESENTATIVE;
        }
        String shippingMethodLabel = null;
        try
        {
            shippingMethodLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.ShippingMethod" );
            if ( shippingMethodLabel == null )
            {
                shippingMethodLabel = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
            }
        }
        catch ( NullPointerException e )
        {
            shippingMethodLabel    = Labels.DEFAULT_SHIPPING_METHOD_LABEL;
        }
        String deliveryTermsLabel = null;
        try
        {
            deliveryTermsLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.sales.salesOrder.DeliveryTerms" );
            if ( deliveryTermsLabel == null )
            {
                deliveryTermsLabel = Labels.DEFAULT_DELIVERY_TERMS_LABEL;
            }
        }
        catch ( NullPointerException e )
        {
            deliveryTermsLabel    = Labels.DEFAULT_DELIVERY_TERMS_LABEL;
        }
        if ( Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() ) ) {
            isClientAirgo = true;
        }
        String heading  = null;
        if ( salesOrder.getIsSample() )
        {
            heading = "Sample";
        }
        else
        {
            heading = "Sales";
        }
        StringBuffer htmlView = new StringBuffer();

        htmlView.append( "<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE><META http-equiv=Content-Type content='text/html; charset=windows-1252'>\n" );

        htmlView.append( "<style type=\"text/css\">" );
        htmlView.append( "#toc a{ font-family: Verdana;font-style : normal ;font-size : 7pt; font-weight :bold;}" );
        htmlView.append( "#toc p{font-family: Verdana;font-style : normal ;font-size : 7pt; font-weight :bold;text-align :center;color :#FFFFFF}" );
        htmlView.append( "#toc {border-style : solid;border-color :#000000 ;border-width :medium }" );
        htmlView.append( "</style></head>\n" );


        htmlView.append( "<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight='0' marginwidth='0'><br>\n" );

        htmlView.append( "<TABLE cellSpacing=0 cellPadding=0 width='100%' border=1 bgcolor='#FFFFFF' align='center' style='FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana'><tr><td>\n" );
        htmlView.append( "<table cellSpacing=0 cellPadding=2 width='100%' border=0 bgcolor='#FFFFFF' align='center' style='FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana'>\n" );
        htmlView.append( "<tr><td colspan='6' align='center'><br></td></tr>\n" );
        if( !changeSummary.equals( "" ) )
            htmlView.append( "<tr><td colspan='6' align='left' bgcolor='#e6e6e6'><b>Change Summary:</b>" + changeSummary + "<br></td></tr>\n" );
        htmlView.append( "<tr><td colspan='6' bgcolor='#ccccff' valign='center' align='center'><SPAN style='FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana'><strong>"+heading+ " Order</strong></td></tr>\n" );

        if ( showLinks )
        {
            htmlView.append( "<tr bgColor='#e6e6e6'><td width='21%'>Created By:</font></td>\n" );
            htmlView.append( "<td width='21%' class='bodytext'>" + ( ( salesOrder.getEnteredById() == null ) ? "" : salesOrder.getEnteredById() ) + "</td>\n" );
            htmlView.append( "<td width='3%'>&nbsp;</td><td width='21%'>Last Updated On:</font></td>\n" );
            htmlView.append( "<td width='21%' class='bodytext'>" + ( ( salesOrder.getEnteredDate() == null ) ? "" : salesOrder.getEnteredDate() ) + "</td>\n" );
            htmlView.append( "<td width='3%'>&nbsp;</td></tr><tr bgColor='#e6e6e6'><td colspan='6' align='center'><br></td></tr>\n" );
        }

        htmlView.append( "<tr bgColor='#e6e6e6'><td width='21%'><font class='NArialL'>Sales Order No :</font></td>\n" );
        htmlView.append( "<td width='21%' class='bodytext'><b>" + salesOrder.getSalesOrderNo() + "</b></td>\n" );
        htmlView.append( "<td width='3%'>&nbsp;</td><td width='21%'>Customer Name :</font></td>" );
        htmlView.append( "<td width='21%' class='bodytext'>" + salesOrder.getCustomerName() + "</td><td></td>" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Change No :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( SalesOrderDAO.loadChangeNo( salesOrder.getSalesOrderId() ) - 1 ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "<td width='3%'>&nbsp;</td><td></td><td></td></tr><tr bgColor='#e6e6e6'><td width='21%'>Customer PO No :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getCustomerPO() == null ) ? "" : salesOrder.getCustomerPO() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Contact Person :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getContactPerson() == null ) ? "" : salesOrder.getContactPerson() ) + "</font></td><td width='3%'>&nbsp;</td></tr>\n" );

        htmlView.append( "<tr bgColor='#e6e6e6'><td width='21%'>"+poRevLabel+ " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getPoRev() == null ) ? "" : salesOrder.getPoRev() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>"+poDateLabel+ " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getPoDate() == null ) ? "" : salesOrder.getPoDate() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "<tr bgColor='#e6e6e6'><td width='21%'>Phone :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getPhoneNumber() == null ) ? "" : salesOrder.getPhoneNumber() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Cell No :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getCellNumber() == null ) ? "" : salesOrder.getCellNumber() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Fax :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getFaxNumber() == null ) ? "" : salesOrder.getFaxNumber() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Email :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getEmail() == null ) ? "" : salesOrder.getEmail() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Sales Person :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getSalesPerson() == null ) ? "" : salesOrder.getSalesPerson() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>"+representativeLabel+ " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getSalesRep() == null ) ? "" : salesOrder.getSalesRep() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );


        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>"+shippingMethodLabel+" :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( ( salesOrder.getShippingMethodName() == null ) || ( salesOrder.getShippingMethodName().trim().length() == 0 ) ) ? "" : salesOrder.getShippingMethodName() + "   #   " + salesOrder.getShippingAccount() ) + "</font></td><td width='3%'>&nbsp;</td><td></td><td></td><td></td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Pay Terms :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getShippingTerms() == null ) ? "" : salesOrder.getShippingTerms() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>"+deliveryTermsLabel+ ":</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getDeliveryTerms() == null ) ? "" : salesOrder.getDeliveryTerms() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Regional Rep :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getRegionalRep() == null ) ? "" : salesOrder.getRegionalRep() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Booking Date :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getSalesOrderDate() == null ) ? "" : salesOrder.getSalesOrderDate() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'> " + endUserLabel + " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getEndCustomer() == null ) ? "" : salesOrder.getEndCustomer() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'> " + endCustomerLabel + " :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getOdm() == null ) ? "" : salesOrder.getOdm() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Billing Address :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getBillingAddress() == null ) ? "" : salesOrder.getBillingAddressAsHTML() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Shipping Address :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getShippingAddress() == null ) ? "" : salesOrder.getShippingAddressAsHTML() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Freight Instructions :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getFreightInstructions() == null ) ? "" : salesOrder.getFreightInstructions() ) + "</font></td><td width='3%'>&nbsp;</td>\n" );
        htmlView.append( "<td width='21%'>Shipping Instructions :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getShippingInstructions() == null ) ? "" : salesOrder.getShippingInstructions() ) + "</font></td><td width='3%'>&nbsp;</td></tr>\n" );

        htmlView.append( "</tr><tr bgColor='#e6e6e6'><td width='21%'>Comments :</font></td>\n" );
        htmlView.append( "<td width='21%'><font class='bodytext'>" + ( ( salesOrder.getComments() == null ) ? "" : salesOrder.getComments() ) + "</font></td><td width='3%'>&nbsp;</td><td></td><td></td><td></td>\n" );
        htmlView.append( "</td></tr><tr><td colspan=6></td></tr><tr><td colspan=6><br></td></tr><tr><td colspan=6>\n" );

        if( presentLineItems.isEmpty() == false )
        {
            htmlView.append( "<TABLE style='FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana' borderColor='#ffffff' cellSpacing='1' cellPadding='3' width='100%' border=0><tr bgColor='#ccccff'>\n" );
            htmlView.append( "<td width='5%' align='center' >PO Line Item</td>\n" );

            htmlView.append( "<td width='5%' align='center' >Line Item</td>\n" );
			htmlView.append( "<td width='7%' align='center' >" );
			if(showLinks == true) { //assuming the mail is going to internal users only. So we need to display mfg part number
				String mfgPartNumberLabel = MessageResources.getMessageResources( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage( "label.mfgPartNumber" );
				if( mfgPartNumberLabel == null ) {
					mfgPartNumberLabel = Labels.DEFAULT_MFG_PART_NUMBER_LABEL;
				}

				htmlView.append( mfgPartNumberLabel );
			} else { //assuming the mail is also going to customers. So we need to display always mktg part number
				String mktgPartNumberLabel = MessageResources.getMessageResources( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage( "label.mktgPartNumber" );
				if( mktgPartNumberLabel == null ) {
					mktgPartNumberLabel = Labels.DEFAULT_MKTG_PART_NUMBER_LABEL;
				}

				htmlView.append( mktgPartNumberLabel );
			}
			htmlView.append( "</td>\n" );
            String customerPartNumberLabel = MessageResources.getMessageResources( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage( "label.customerPartNumber" );
            if( customerPartNumberLabel == null )
            {
                customerPartNumberLabel = Labels.DEFAULT_CUSTOMER_PART_NUMBER_LABEL;
            }
            htmlView.append( "<td width='7%' align='center' >" + customerPartNumberLabel + "</td>\n" );
            String  labelNumberLabel = null;
            try
            {
                labelNumberLabel = MessageResources.getMessageResources ( Labels.APPLICATION_RESOURCE_PROPERTIES ).getMessage ( "label.labelNumber" );
                if ( labelNumberLabel == null )
                {
                    labelNumberLabel = Labels.DEFAULT_LABEL_NUMBER_LABEL;
                }
            }
            catch ( NullPointerException e )
            {
                labelNumberLabel  = Labels.DEFAULT_LABEL_NUMBER_LABEL;
            }
            if ( isClientAirgo ) {
                htmlView.append( "<td width='7%' align='center'>" + labelNumberLabel + "</td>\n" );
            }
            htmlView.append( "<td width='8%' align='center' >Description</td>\n" );
            htmlView.append( "<td width='10%' align='center' >Taxable</td>\n" );
            htmlView.append( "<td width='10%' align='center' >Request Date</td>\n" );
            htmlView.append( "<td width='5%' align='center' >Quantity</td>\n" );
            htmlView.append( "<td width='10%' align='center' >Price </td>\n" );
            htmlView.append( "<td width='10%' align='center' >Amount</td>\n" );
            htmlView.append( "<td width='10%' align='center' >Sugg Ship Date</td>\n" );
            htmlView.append( "<td width='10%' align='center' >Scheduled Ship Date</td>\n" );
            htmlView.append( "<td width='10%' align='center' >Revised Ship Date</td>\n" );
            htmlView.append( "<td width='14%' align='center' >Holds<br>&nbsp;Mkg&nbsp;&nbsp;Fin&nbsp;&nbsp;Ops&nbsp;&nbsp;Sales&nbsp;</td>\n" );
            htmlView.append( "<td width='6%' align='center' >Expedite <br> Fee</td></tr>\n" );

            Iterator lineItems = presentLineItems.iterator();
            LineItem lineItem = null;
            String opHold = "";
            String finHold = "";
            String mkgHold = "";
            String salesHold = "";
            while( lineItems.hasNext() )
            {
                lineItem = ( LineItem ) lineItems.next();
                lineItem = SalesOrderDAO.loadHoldsForLineItem( lineItem );

                opHold = lineItem.getOperationsHold();
                if( ( opHold == null ) || ( opHold.trim().length() == 0 ) )
                {
                    opHold = "&nbsp;";
                }
                else if( "0".equalsIgnoreCase( opHold ) )
                {
                    opHold = "X";
                }

                finHold = lineItem.getFinanceHold();
                if( ( finHold == null ) || ( finHold.trim().length() == 0 ) )
                {
                    finHold = "&nbsp;";
                }
                else if( "0".equalsIgnoreCase( finHold ) )
                {
                    finHold = "X";
                }

                mkgHold = lineItem.getMarketingHold();
                if( ( mkgHold == null ) || ( mkgHold.trim().length() == 0 ) )
                {
                    mkgHold = "&nbsp;";
                }
                else if( "0".equalsIgnoreCase( mkgHold ) )
                {
                    mkgHold = "X";
                }

                salesHold = lineItem.getSalesHold();
                if( ( salesHold == null ) || ( salesHold.trim().length() == 0 ) )
                {
                    salesHold = "&nbsp;";
                }
                else if( "0".equalsIgnoreCase( salesHold ) )
                {
                    salesHold = "X";
                }

                htmlView.append( "<tr bgColor='#e6e6e6'><td width='5%' align='center'><font class='bodytext'>" + lineItem.getPoLineItemNo() + "</font></td>\n" );
                htmlView.append( "<td width='5%' align='center' nowrap><font class='bodytext'>" + lineItem.getLineItemNo() + "</font></td>\n" );
                htmlView.append( "<td width='7%' align='center' nowrap><font class='bodytext'>");
				if(showLinks == true) { //assuming the mail is going to internal users only. So we need to display mfg part number
					htmlView.append( lineItem.getManufacturingPartNo() );
				} else { //assuming the mail is also going to customers. So we need to display always mktg part number
					htmlView.append( lineItem.getMarketingPartNo() );
				}
				htmlView.append( "</font></td>\n" );
                htmlView.append( "<td width='7%' align='center' nowrap><font class='bodytext'>" + lineItem.getCustomerPartNo() + "</font></td>\n" );
                if ( isClientAirgo ) {
                    htmlView.append( "<td width='7%' align='center' nowrap><font class='bodytext'>" + ( lineItem.getLabelNumber() == null ? "" : lineItem.getLabelNumber() ) + "</font></td>\n" );
                }
                String desc = lineItem.getLineItemDescription();
                if( desc == null ) desc = "";
                htmlView.append( "<td width='8%' align='center' nowrap><font class='bodytext'>" + desc + "</font></td>\n" );
                htmlView.append( "<td width='10%' align='center'><font class='bodytext'>" + ( ( lineItem.getIsTaxableAsString() == null ) ? "" : lineItem.getIsTaxableAsString() ) + "</font></td>\n" );
                htmlView.append( "<td width='10%' align='center' ><font class='bodytext'>" + ( ( lineItem.getRequestDate() == null ) ? "" : lineItem.getRequestDate() ) + "</font></td>\n" );
                htmlView.append( "<td width='5%' align='right' ><font class='bodytext'>" + StringUtils.formatUnits( lineItem.getQuantity() ) + "</font></td>\n" );
                htmlView.append( "<td  align='right' nowrap><font class='bodytext'>" + StringUtils.formatAmountWithNoOfDecimals( lineItem.getUnitPriceAsDouble() ) + "</font></td>\n" );
                htmlView.append( "<td  align='right' nowrap><font class='bodytext'>" + StringUtils.formatAmountWithNoOfDecimals( lineItem.getAmountAsDouble() ) + "</font></td>\n" );

                htmlView.append( "<td width='10%' align='center' ><font class='bodytext'>" + ( ( lineItem.getSuggScheduleDate() == null ) ? "" : lineItem.getSuggScheduleDate() ) + "</font></td>\n" );
                htmlView.append( "<td width='10%' align='center' ><font class='bodytext'>" + ( ( lineItem.getScheduleDate() == null ) ? "" : lineItem.getScheduleDate() ) + "</font></td>\n" );
                htmlView.append( "<td width='10%' align='center'><font class='bodytext'>" + ( ( lineItem.getRevisedDate() == null ) ? "" : lineItem.getRevisedDate() ) + "</font></td>\n" );
                htmlView.append( "<td width='14%' align='center'><font class='bodytext'>&nbsp;[" + mkgHold.trim() + "]&nbsp;&nbsp;[" + finHold.trim() + "]&nbsp;&nbsp;[" + opHold.trim() + "]&nbsp;&nbsp;[" + salesHold.trim() + "]&nbsp;</font></td>\n" );
                boolean expediteValue = lineItem.getIsExpedite();
                String expediteFee = null;
                if( expediteValue == true )
                {
                    expediteFee = "Yes";
                }
                else
                {
                    expediteFee = "No";
                }

                htmlView.append( "<td width='6%' align='center'><font class='bodytext'>" + expediteFee + "</font></td></tr>\n" );

                status_temp = ( lineItem.getStatus() ).trim();
                if( ( "HOLD".equalsIgnoreCase( status_temp ) ) || ( "PENDING".equalsIgnoreCase( status_temp ) ) )
                {
                    sales_order_status = true;
                }
            }
            htmlView.append( "</table>" );
        }
        htmlView.append( "</td></tr><tr><td colspan='6' align='center'><br></td></tr>" );
        if ( showLinks )
        {
            htmlView.append( "<tr><td colspan='6' align='center'><a href='http://" ).append( ConfigManager.getChipTracHost() ).append( "/" ).append( ConfigManager.getChipTracContext() );


            if( sales_order_status )
                htmlView.append( SALES_ORDER_URI_1 ).append( salesOrderId ).append("&isSample=").append((isSample?0:1)).append( "'><strong>Please click here to go to the sales order page</strong></a></td></tr>" );
            else
                htmlView.append( SALES_ORDER_URI_2 ).append( salesOrderId ).append("&isSample=").append((isSample?0:1)).append( "'><strong>Please click here to go to the sales order page</strong></a></td></tr>" );
        }

        htmlView.append( "</table></td></tr></table>\n" );
        if( showLinks )
        {
            htmlView.append( "<br><br><br><br><table width='70%' border='0' style='FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana'>" );
            htmlView.append( "<tr><td>___________________________________________________________</td></tr>" );
            htmlView.append( "<tr><td>You are receiving this email because you have the access rights to</td></tr>" );
            htmlView.append( "<tr><td>approve a sales order from ChipTrac System. If you no longer wish you receive this email</td></tr>" );
            htmlView.append( "<tr><td>Please contact your system administrator.</td></tr></table>" );
        }
        htmlView.append( "<br><br></BODY></HTML>\n" );

        return htmlView.toString();
    }

    private static String totalQty = null;
    private static String totalAmount = null;

    public String getTotalQuantity()
    {
        return totalQty;
    }

    public void setTotalQty( String totalQty )
    {
        this.totalQty = totalQty;
    }

    public String getTotalAmount()
    {
        return totalAmount;
    }

    public void setTotalAmount( String totalAmount )
    {
        this.totalAmount = totalAmount;
    }

    public String getSalesTaxType()
    {
        return salesTaxType;
    }

    public void setSalesTaxType( String salesTaxType )
    {
        this.salesTaxType = salesTaxType;
    }

    public float getSubTotal()
    {
        return subTotal;
    }

    public String getSubTotalAsString()
    {
        return StringUtils.formatAmountWithNoOfDecimals( subTotalAsDouble);
    }

    public void setSubTotal( float subTotal )
    {
        this.subTotal = subTotal;
    }

    public float getSalesTax()
    {
        return salesTax;
    }

    public String getSalesTaxAsString()
    {
        return StringUtils.formatAmountWithNoOfDecimals( salesTaxAsDouble );

    }

    public void setSalesTax( float salesTax )
    {
        this.salesTax = salesTax;
    }

    public String getFrieghtAsString()
    {
        return StringUtils.formatAmountWithNoOfDecimals( frieghtAsDouble);

    }

    public float getFrieght()
    {
        return frieght;
    }

    public void setFrieght( float frieght )
    {
        this.frieght = frieght;
    }

    public String getMiscAsString()
    {
        return StringUtils.formatAmountWithNoOfDecimals( miscAsDouble );
    }

    public float getMisc()
    {
        return misc;
    }

    public void setMisc( float misc )
    {
        this.misc = misc;
    }

    public float getOrderTotal()
    {
        return orderTotal;
    }

    public String getOrderTotalAsString()
    {
        return StringUtils.formatAmountWithNoOfDecimals( orderTotalAsDouble );

    }

    public void setOrderTotal( float orderTotal )
    {
        this.orderTotal = orderTotal;
    }

    public double getSubTotalAsDouble()
    {
        return subTotalAsDouble;
    }

    public void setSubTotalAsDouble( double subTotalAsDouble )
    {
        this.subTotalAsDouble = subTotalAsDouble;
    }

    public double getSalesTaxAsDouble()
    {
        return salesTaxAsDouble;
    }

    public void setSalesTaxAsDouble( double salesTaxAsDouble )
    {
        this.salesTaxAsDouble = salesTaxAsDouble;
    }

    public double getFrieghtAsDouble()
    {
        return frieghtAsDouble;
    }

    public void setFrieghtAsDouble( double frieghtAsDouble )
    {
        this.frieghtAsDouble = frieghtAsDouble;
    }

    public double getMiscAsDouble()
    {
        return miscAsDouble;
    }

    public void setMiscAsDouble( double miscAsDouble )
    {
        this.miscAsDouble = miscAsDouble;
    }

    public double getOrderTotalAsDouble()
    {
        return orderTotalAsDouble;
    }

    public void setOrderTotalAsDouble( double orderTotalAsDouble )
    {
        this.orderTotalAsDouble = orderTotalAsDouble;
    }

    public String getMiscName()
    {
        return miscName;
    }

    public void setMiscName( String miscName )
    {
        if( ( miscName != null ) && ( miscName.length() > 0 ) )
            this.miscName = miscName;
    }

    public void setFinalSubTotal( double finalSubTotal )
    {
        this.finalSubTotal = finalSubTotal;
    }

    public double getFinalSubTotal()
    {
        return finalSubTotal;
    }

    public String getFinalSubTotalAsString()
    {
        return StringUtils.formatAmountWithNoOfDecimals( finalSubTotal );
    }

    public void setFinalSalesTax( double finalSalesTax )
    {
        this.finalSalesTax = finalSalesTax;
    }

    public double getFinalSalesTax()
    {
        return finalSalesTax;
    }

    public String getFinalSalesTaxAsString()
    {
        return StringUtils.formatAmountWithNoOfDecimals( finalSalesTax );
    }

    public void setFinalOrderTotal( double finalOrderTotal )
    {
        this.finalOrderTotal = finalOrderTotal;
    }

    public double getFinalOrderTotal()
    {
        return finalOrderTotal;
    }

    public String getFinalOrderTotalAsString()
    {
        return StringUtils.formatAmountWithNoOfDecimals( finalOrderTotal );
    }

    public String getNewShippingMethod()
    {
        return newShippingMethod;
    }

    public void setNewShippingMethod( String newShippingMethod )
    {
        this.newShippingMethod = newShippingMethod;
    }

    public Address getBillingAddressAsObject()
    {
        return billingAddressAsObject;
    }

    public void setBillingAddressAsObject( Address address )
    {
        billingAddressAsObject = address;
    }

    public Address getShippingAddressAsObject()
    {
        return shippingAddressAsObject;
    }

    public void setShippingAddressAsObject( Address address )
    {
        shippingAddressAsObject = address;
    }

    public Address getClientAddressAsObject()
    {
        return clientAddressAsObject;
    }

    public void setClientAddressAsObject( Address address )
    {
        clientAddressAsObject = address;
    }

    public String getClientName()
    {
        return clientName;
    }

    public void setClientName( String clientName )
    {
        this.clientName = clientName;
    }

    public static void main( String[] args ) throws Exception
    {
        SalesOrder salesOrder = new SalesOrder();
        String message = salesOrder.getHtmlView( 39 );

        String from = "balaram@scalarsoft.com";
        String to = "balaram@scalarsoft.com";
        String subject = "sales order";
        Mailer.send( from, to, subject, message );
    }

    public String getRegionalRep()
    {
        return regionalRep;
    }

    public void setRegionalRep( String regionalRep )
    {
        this.regionalRep = regionalRep;
    }

    public String getShippingTerms()
    {
        return shippingTerms;
    }

    public void setShippingTerms( String shippingTerms )
    {
        this.shippingTerms = shippingTerms;
    }

    public ArrayList getAllShippingTerms()
    {
        return allShippingTerms;
    }

    public void setAllShippingTerms( ArrayList list )
    {
        allShippingTerms = list;
    }

    public String getNewShippingTerms()
    {
        return newShippingTerms;
    }

    public void setNewShippingTerms( String newShippingTerms )
    {
        this.newShippingTerms = newShippingTerms;
    }

    public String getDeliveryTerms()
    {
        return deliveryTerms;
    }

    public void setDeliveryTerms( String deliveryTerms )
    {
        this.deliveryTerms = deliveryTerms;
    }

    public void setSalesTaxValue( float salesTaxValue )
    {
        this.salesTaxValue = salesTaxValue;
    }

    public float getSalesTaxValue()
    {
        return this.salesTaxValue;
    }
    /**
     * Returns the release number of this sales order. Used when sales is integrated with eBackOffice
     *
     * @return salesOrderReleaseNumber
     */
    public int getSalesOrderReleaseNumber()
    {
        return salesOrderReleaseNumber;
    }

    /**
     * sets the release number of this sales order. Used when sales is integrated with eBackOffice
     *
     * @param salesOrderReleaseNumber
     */
    public void setSalesOrderReleaseNumber( int salesOrderReleaseNumber )
    {
        this.salesOrderReleaseNumber = salesOrderReleaseNumber;
    }

    /**
     * Returns the customer number of the sales order customer
     *
     * @return customerNumber
     */
    public String getCustomerNumber()
    {
        return customerNumber;
    }

    /**
     * sets the sales order customer number
     *
     * @param customerNumber
     */
    public void setCustomerNumber( String customerNumber )
    {
        this.customerNumber = customerNumber;
    }

    /**
     * Returns the Shipping Address Code when sales is integrated with Epicore
     *
     * @return  epicoreShippingAddressCode
     */
    public String getEpicoreShippingAddressCode()
    {
        return epicoreShippingAddressCode;
    }

    /**
     * Sets the shipping address code when sales is integrated with Epicore
     *
     * @param epicoreShippingAddressCode
     */
    public void setEpicoreShippingAddressCode( String epicoreShippingAddressCode )
    {
        this.epicoreShippingAddressCode = epicoreShippingAddressCode;
    }

    /**
     * Returns the required ship date of the sales order. This is used when sales is integrated
     * with Epicore because, required ship date is given for the sales order in Epicore unlike
     * chiptrac where required ship date is given for line items individually.
     *
     * @return requiredShipDate
     */
    public String getRequiredShipDate()
    {
        return requiredShipDate;
    }

    /**
     * Sets the required ship date of the sales order. This is used when sales is integrated
     * with Epicore because, required ship date is given for the sales order in Epicore unlike
     * chiptrac where required ship date is given for line items individually.
     *
     * @param requiredShipDate
     */
    public void setRequiredShipDate( String requiredShipDate )
    {
        this.requiredShipDate = requiredShipDate;
    }

    /**
     * Returns the schedule ship date of the sales order. This is used when sales is integrated
     * with Epicore because, schedule ship date is given for the sales order in Epicore unlike
     * chiptrac where required ship date is given for line items individually.
     *
     * @return scheduleShipDate
     */
    public String getScheduleShipDate()
    {
        return scheduleShipDate;
    }

    /**
     * Sets the schedule ship date of the sales order. This is used when sales is integrated
     * with Epicore because, schedule ship date is given for the sales order in Epicore unlike
     * chiptrac where required ship date is given for line items individually.
     *
     * @param scheduleShipDate
     */
    public void setScheduleShipDate( String scheduleShipDate )
    {
        this.scheduleShipDate = scheduleShipDate;
    }

    //end of additions by rohan on May 7th 2004

    //Added by rohan on May19th 2004

    /**
     * returns if there is epicore hold on the sales order
     *
     * @return epicoreSalesOrderHold
     */
    public boolean isEpicoreHold()
    {
        return epicoreHold;
    }

    /**
     * Sets the epicore hold on the sales order
     *
     * @param epicoreHold
     */
    public void setEpicoreHold( boolean epicoreHold )
    {
        this.epicoreHold = epicoreHold;
    }

    /**
     * Returns the Epicore Sales order status
     *
     * @return salesOrderStatus
     */
    public String getEpicoreSalesOrderStatus()
    {
        return epicoreSalesOrderStatus;
    }

    /**
     * Sets the Epicore sales order status
     *
     * @param epicoreSalesOrderStatus
     */
    public void setEpicoreSalesOrderStatus( String epicoreSalesOrderStatus )
    {
        this.epicoreSalesOrderStatus = epicoreSalesOrderStatus;
    }

    //Don't use this method to display billing and shipping addresses..use the method in Address class.
    public static String getAddressAsString( Address address )
    {
        StringBuffer tempAddress = new StringBuffer( "" );
        String contactPerson = address.getContactPerson();
        String address1 = address.getAddress1();
        String address2 = address.getAddress2();
        String address3 = address.getAddress3();
        String address4 = address.getAddress4();
        String city = address.getCity();
        String zipCode = address.getZipCode();
        String state = address.getState();
        String country = address.getCountry();
        String phoneNumber = address.getPhoneNumber();
        String cellNumber = address.getCellNumber();
        String faxNumber = address.getFaxNumber();
        String email = address.getEmail();

        if( contactPerson != null && !( contactPerson.trim().equals( "" ) ) )
        {
            tempAddress.append( contactPerson + "\n" );
        }

        if( address1 != null && !( address1.trim().equals( "" ) ) )
        {
            tempAddress.append( address1 + "\n" );
        }

        if( address2 != null && !( address2.equals( "" ) ) )
        {
            tempAddress.append( address2 + "\n" );
        }
        if( address3 != null && !( address3.equals( "" ) ) )
        {
            tempAddress.append( address3 + "\n" );
        }
        if( address4 != null && !( address4.equals( "" ) ) )
        {
            tempAddress.append( address4 + "\n" );
        }
        if( city != null && !( city.equals( "" ) ) )
        {
            tempAddress.append( city + "\n" );
        }
        if( state != null && !( state.equals( "" ) ) )
        {
            tempAddress.append( state );
        }


        if( zipCode != null && !( zipCode.equals( "" ) ) )
        {
            if( state != null && !( state.equals( "" ) ) )
            {
                tempAddress.append( " - " );
            }
            tempAddress.append( zipCode );
        }

        if( country != null && !( country.equals( "" ) ) )
        {
            if( ( zipCode != null && !( zipCode.equals( "" ) ) ) || ( state != null && !( state.equals( "" ) ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( country );
        }
        tempAddress.append( ( phoneNumber != null && !( phoneNumber.equals( "" ) ) ) ? "\n\nTel:" + phoneNumber : "" );
        tempAddress.append( ( cellNumber != null && !( cellNumber.equals( "" ) ) ) ? "\nCell:" + cellNumber : "" );
        tempAddress.append( ( faxNumber != null && !( faxNumber.equals( "" ) ) ) ? "\nFax:" + faxNumber : "" );
        tempAddress.append( ( email != null && !( email.equals( "" ) ) ) ? "\nEmail:" + email : "" );
        return tempAddress.toString();
    }

    public String getBillingAddressAsHTML()
    {
        StringBuffer tempAddress = new StringBuffer( "" );
        if ( billingAddress != null )
        {
            for( int i = 0; i < billingAddress.length(); i++ )
            {
                char ch = billingAddress.charAt( i );
                if( ch == '\n' )
                {
                    tempAddress.append( "<br>" );
                }
                else
                {
                    tempAddress.append( ch );
                }
            }
        }
        billingAddressAsHTML = tempAddress.toString();
        return billingAddressAsHTML;
    }

    public String getShippingAddressAsHTML()
    {
        StringBuffer tempAddress = new StringBuffer( "" );
        if ( shippingAddress != null )
        {
            for( int i = 0; i < shippingAddress.length(); i++ )
            {
                char ch = shippingAddress.charAt( i );
                if( ch == '\n' )
                {
                    tempAddress.append( "<br>" );
                }
                else
                {
                    tempAddress.append( ch );
                }
            }
        }
        shippingAddressAsHTML = tempAddress.toString();
        return shippingAddressAsHTML;
    }

    public static String getClientAddressAsString( Address address )
    {
        StringBuffer tempAddress = new StringBuffer( "" );
        String address1 = address.getAddress1();
        String address2 = address.getAddress2();
        String address3 = address.getAddress3();
        String address4 = address.getAddress4();
        String city = address.getCity();
        String zipCode = address.getZipCode();
        String state = address.getState();
        String country = address.getCountry();
        String phno = address.getPhoneNumber();
        String faxno = address.getFaxNumber();
        String countryName = address.getCountry();

        if( address1 != null && !( address1.trim().equals( "" ) ) )
        {
            tempAddress.append( address1 );
        }
        if( address2 != null && !( address2.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( "\n" );
            }
            tempAddress.append( address2 );
        }
        if( address3 != null && !( address3.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( "\n" );
            }
            tempAddress.append( address3 );
        }
        if( address4 != null && !( address4.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( "\n" );
            }
            tempAddress.append( address4 );
        }
        if( city != null && !( city.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( "\n" );
            }
            tempAddress.append( city );
        }
        if( state != null && !( state.equals( "" ) ) )
        {
            if( city == null || city.trim().length() == 0 )
            {
                tempAddress.append( "\n" );
            }
            else if( city != null && !( city.equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( state );
        }

        if( zipCode != null && !( zipCode.equals( "" ) ) )
        {
            if( ( state != null && !( state.equals( "" ) ) ) || ( city != null && !( city.equals( "" ) ) ) )
            {
                tempAddress.append( " - " );
            }
            tempAddress.append( zipCode );
        }
        if( country != null && !( country.equals( "" ) ) )
        {
            if( ( zipCode != null && !( zipCode.equals( "" ) ) ) || ( state != null && !( state.equals( "" ) ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( country );
        }

        if( phno != null && !( phno.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( "\n" );
            }
            tempAddress.append( " Tel:" ).append( phno );
        }
        if( faxno != null && !( faxno.equals( "" ) ) )
        {
            if( phno == null || phno.trim().length() == 0 )
            {
                tempAddress.append( "\n" );
            }
            else if( phno != null && !( phno.equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( "Fax:" ).append( faxno );
        }
        return tempAddress.toString();
    }

    public String getClientAddress()
    {
        return clientAddress;
    }

    public void setClientAddress( String clientAddress )
    {
        this.clientAddress = clientAddress;
    }
    public int getApprovedCount() {
        return approvedCount;
    }

    public void setApprovedCount(int approvedCount) {
        this.approvedCount = approvedCount;
    }

    public String getPoRev() {
                    return poRev;
    }

    public void setPoRev(String poRev) {
        this.poRev = poRev;
    }

    public String getPoDate() {
        if ( poDate == null ) {
            poDate = "";
        }

        return poDate;
    }

    public void setPoDate(String poDate) {
        this.poDate = poDate;
    }

    public ArrayList getAllDeliveryTerms() {
        return allDeliveryTerms;
    }

    public void setAllDeliveryTerms(ArrayList allDeliveryTerms) {
        this.allDeliveryTerms = allDeliveryTerms;
    }

    //To get Client address in HTML form
    public String getClientAddressAsHTML()
    {
        StringBuffer tempClientAddress = new StringBuffer( "" );
        for( int i = 0; i < clientAddress.length(); i++ )
        {
            char ch = clientAddress.charAt( i );
            if( ch == '\n' )
            {
                tempClientAddress.append( "<br>" );
            }
            else
            {
                tempClientAddress.append( ch );
            }
        }
        clientAddressAsHTML = tempClientAddress.toString();
        return clientAddressAsHTML;
    }

    /*To display Client Address in required format after Terms and Conditions in Sales Order Acknowledgement screen */
    public static String getClientAddressToLoad( Address address )
    {
        StringBuffer tempAddress = new StringBuffer( "" );
        String address1 = address.getAddress1();
        String address2 = address.getAddress2();
        String address3 = address.getAddress3();
        String address4 = address.getAddress4();
        String city = address.getCity();
        String zipCode = address.getZipCode();
        String state = address.getState();
        String country = address.getCountry();
        String phno = address.getPhoneNumber();
        String faxno = address.getFaxNumber();
        String countryName = address.getCountry();


        if( address1 != null && !( address1.trim().equals( "" ) ) )
        {
            tempAddress.append( address1 );
        }
        if( address2 != null && !( address2.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( address2 );
        }
        if( address3 != null && !( address3.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( address3 );
        }
        if( address4 != null && !( address4.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( address4 );
        }

        if( city != null && !( city.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( city );
        }
        if( state != null && !( state.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( state );
        }
        if( zipCode != null && !( zipCode.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( " - " );
            }
            tempAddress.append( zipCode );
        }

        if( country != null && !( country.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( country );
        }

        if( phno != null && !( phno.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( "Tel:" ).append( phno );
        }
        if( faxno != null && !( faxno.equals( "" ) ) )
        {
            if( tempAddress.toString() != null && !( tempAddress.toString().equals( "" ) ) )
            {
                tempAddress.append( ", " );
            }
            tempAddress.append( "Fax:" ).append( faxno );
        }
        return tempAddress.toString();
    }

    /**
     * This method truncates the data which cannot be saved in the GP database
     */
    public void prepareSalesOrderForGPInsertion()
    {
        if( this.getSalesOrderNo() == null )
        {
            this.setSalesOrderNo( "" );
        }
        else if( this.getSalesOrderNo().trim().length() > 21 )
        {
            this.setSalesOrderNo( this.getSalesOrderNo().trim().substring( 0, 20 ) );
        }

        if( this.getCustomerPO() == null )
        {
            this.setCustomerPO( "" );
        }
        else if( this.getCustomerPO().trim().length() > 21 )
        {
            this.setCustomerPO( this.getCustomerPO().trim().substring( 0, 20 ) );
        }

        if( this.getShippingTerms() == null )
        {
            this.setShippingTerms( "" );
        }
        else if( this.getShippingTerms().trim().length() > 21 )
        {
            this.setShippingTerms( this.getShippingTerms().trim().substring( 0, 20 ) );
        }

        if( this.getShippingMethod() == null )
        {
            this.setShippingMethod( "" );
        }
        else if( this.getShippingMethod().trim().length() > 15 )
        {
            this.setShippingMethod( this.getShippingMethod().trim().substring( 0, 15 ) );
        }

        if( this.getShippingMethodName() == null )
        {
            this.setShippingMethodName( "" );
        }
        else if( this.getShippingMethodName().trim().length() > 15 )
        {
            this.setShippingMethodName( this.getShippingMethodName().trim().substring( 0, 15 ) );
        }

        if( this.getShippingAccount() == null )
        {
            this.setShippingAccount( "" );
        }
        else if( this.getShippingAccount().trim().length() > 15 )
        {
            this.setShippingAccount( this.getShippingAccount().trim().substring( 0, 15 ) );
        }

        if( this.getContactPerson() == null )
        {
            this.setContactPerson( "" );
        }
        else if( this.getContactPerson().trim().length() > 31 )
        {
            this.setContactPerson( this.getContactPerson().trim().substring( 0, 30 ) );
        }

        if( this.getSalesPerson() == null )
        {
            this.setSalesPerson( "" );
        }
        else if( this.getSalesPerson().trim().length() > 15 )
        {
            this.setSalesPerson( this.getSalesPerson().trim().substring( 0, 14 ) );
        }

        if( this.getEnteredByName() == null )
        {
            this.setEnteredByName( "" );
        }
        else if( this.getEnteredByName().trim().length() > 15 )
        {
            this.setEnteredByName( this.getEnteredByName().trim().substring( 0, 14 ) );
        }

        if( this.getSalesTaxType() == null )
        {
            this.setSalesTaxType( "" );
        }
        else if( this.getSalesTaxType().trim().length() > 15 )
        {
            this.setSalesTaxType( this.getSalesTaxType().trim().substring( 0, 14 ) );
        }

        if( this.getPhoneNumber() == null )
        {
            this.setPhoneNumber( "" );
        }
        else if( this.getPhoneNumber().trim().length() > 21 )
        {
            this.setPhoneNumber( this.getPhoneNumber().trim().substring( 0, 20 ) );
        }

        if( this.getFaxNumber() == null )
        {
            this.setFaxNumber( "" );
        }
        else if( this.getFaxNumber().trim().length() > 21 )
        {
            this.setFaxNumber( this.getFaxNumber().trim().substring( 0, 20 ) );
        }

        if( this.getEmail() == null )
        {
            this.setEmail( "" );
        }
        else if( this.getEmail().trim().length() > 21 )
        {
            this.setEmail( this.getEmail().trim().substring( 0, 20 ) );
        }
    }

    public String toString()
    {
        StringBuffer sb = new StringBuffer();
        sb.append( "SO#=" + salesOrderNo + "; CustName=" + customerName + "; EndUser=" + endUser );
        sb.append( "; PO#=" + customerPo + "; BookDate=" + bookingDate + "\n" );
        sb.append( "; Ship-Method-Name=" + shippingMethodName + "; Ship-Account=" + shippingAccount + "\n" );
        return sb.toString();
    }

    public String getFormattedAddressAirgo( Address address )
	{
		StringBuffer formatAddress = new StringBuffer();

        if( address != null )
        {
            if( address.getAddress1() != null && ( address.getAddress1().trim().length() != 0 ) ){
                formatAddress.append ( address.getAddress1() );
            }
            if( address.getAddress1() != null && ( address.getAddress1().trim().length() != 0 )
                && address.getAddress2() != null && ( address.getAddress2().trim().length() != 0 ) ){
                formatAddress.append ( ", " );
            }
            if( address.getAddress2() != null && ( address.getAddress2().trim().length() != 0 ) ){
                formatAddress.append ( address.getAddress2() );
            }
            if( ( address.getAddress3() != null && !"".equalsIgnoreCase(address.getAddress3().trim()) )
                  || ( address.getAddress4() != null && !"".equalsIgnoreCase(address.getAddress4().trim()) ) ) {
                formatAddress.append ( "<BR>" );
            }
            if( address.getAddress3() != null && ( address.getAddress3().trim().length() != 0 ) ){
                formatAddress.append ( address.getAddress3 () );
            }
            if( address.getAddress3() != null && !"".equals(address.getAddress3().trim())
                && address.getAddress4() != null && !"".equals(address.getAddress4().trim())) {
                formatAddress.append ( ", " );
            }
            if( address.getAddress4() != null && ( address.getAddress4().trim().length() != 0 ) ){
                formatAddress.append ( address.getAddress4 () );
            }

            StringBuffer cityStateZip = new StringBuffer ( "" );

            if ( address.getCity() != null && !"".equals( address.getCity() ) ) {
                cityStateZip.append ( address.getCity () );
            }

            if ( address.getCity() != null && !"".equals( address.getCity() )
                 && ( (  address.getState() != null && !"".equals(address.getState()))
                 || ( address.getZipCode()!= null  && !"".equals(address.getZipCode())) ) ) {
                cityStateZip.append ( ", " );
            }

            if ( address.getState() != null && !"".equals( address.getState() ) ) {
                cityStateZip.append( address.getState () );
            }

            if ( address.getState() != null && !"".equals( address.getState() )
                 && address.getZipCode () != null && !"".equals( address.getZipCode () ) ) {
                cityStateZip.append ( " - " );
            }

            if ( address.getZipCode()!= null && !"".equals( address.getZipCode() ) ) {
                cityStateZip.append ( address.getZipCode () );
            }

            if ( (  ( address.getCity() != null && !"".equals(address.getCity())  )
                    || ( address.getState() != null && !"".equals(address.getState()) )
                    || ( address.getZipCode() != null &&  !"".equals(address.getZipCode()) ) )
                    && address.getCountry() != null && !"".equalsIgnoreCase( address.getCountry() ) )

            {
                cityStateZip.append ( ", " );
                cityStateZip.append ( address.getCountry () );
            }
            else  if ( address.getCountry() != null && !"".equals(address.getCountry() ) ) // added by sujan on 23rd dec 2004. if city,state,zipcode r empty
            {
                cityStateZip.append ( address.getCountry() );
            }
            if( cityStateZip != null && cityStateZip.toString().trim().length() > 0  )
            {
                formatAddress.append ( "<BR>" + cityStateZip );
            }

            StringBuffer phFax = new StringBuffer ();

            if( address.getPhoneNumber() != null && !"".equals( address.getPhoneNumber() ) ) {
                phFax.append ( "T: " + address.getPhoneNumber () );
            }

            if( address.getPhoneNumber() != null && !"".equals( address.getPhoneNumber() )
                &&  address.getFaxNumber() != null && !"".equals ( address.getFaxNumber() ) ) {
                phFax.append ( ",&nbsp;" );
            }

            if( address.getFaxNumber() != null && !"".equals( address.getFaxNumber() ) ) {
                phFax.append ( "F: " + address.getFaxNumber () );
            }

            if( phFax != null && phFax.toString().trim().length() > 0  ) {
                formatAddress.append ( "<BR>" + phFax );
            }

            if(  address.getEmail() != null && address.getEmail().trim().length() > 0 ) {
                formatAddress.append ( "<BR>" +  "Email: "+ address.getEmail() );
            }

        }
        return formatAddress.toString() ;

	}

    public String getClientAddrWithOutEmailObjFormattedAirgo()
	{
		Address address = this.getClientAddressAsObject();
		StringBuffer formatAddress = new StringBuffer();

        if( address != null )
        {
            if( this.getClientName() != null && this.getClientName().trim().length() > 0 ) {
                if( ( address.getAddress1() != null && !address.getAddress1().trim().equalsIgnoreCase( "" ) )
                      || ( address.getAddress2() != null && !address.getAddress2().trim().equalsIgnoreCase( "" ) ) ) {
                    formatAddress.append ( "<BR>" );
                }
            }
            if( address.getAddress1() != null && ( address.getAddress1().trim().length() != 0 ) ){
                formatAddress.append ( address.getAddress1() );
            }
            if( address.getAddress1() != null && ( address.getAddress1().trim().length() != 0 )
                && address.getAddress2() != null && ( address.getAddress2().trim().length() != 0 ) ){
                formatAddress.append ( ", " );
            }
            if( address.getAddress2() != null && ( address.getAddress2().trim().length() != 0 ) ){
                formatAddress.append ( address.getAddress2() );
            }
            if( ( address.getAddress3() != null && !"".equalsIgnoreCase(address.getAddress3().trim()) )
                  || ( address.getAddress4() != null && !"".equalsIgnoreCase(address.getAddress4().trim()) ) ) {
                formatAddress.append ( "<BR>" );
            }
            if( address.getAddress3() != null && ( address.getAddress3().trim().length() != 0 ) ){
                formatAddress.append ( address.getAddress3 () );
            }
            if( address.getAddress3() != null && !"".equals(address.getAddress3().trim())
                && address.getAddress4() != null && !"".equals(address.getAddress4().trim())) {
                formatAddress.append ( ", " );
            }
            if( address.getAddress4() != null && ( address.getAddress4().trim().length() != 0 ) ){
                formatAddress.append ( address.getAddress4 () );
            }

            StringBuffer cityStateZip = new StringBuffer ( "" );

            if ( address.getCity() != null && !"".equals( address.getCity() ) ) {
                cityStateZip.append ( address.getCity () );
            }

            if ( address.getCity() != null && !"".equals( address.getCity() )
                 && ( (  address.getState() != null && !"".equals(address.getState()))
                 || ( address.getZipCode()!= null  && !"".equals(address.getZipCode())) ) ) {
                cityStateZip.append ( ", " );
            }

            if ( address.getState() != null && !"".equals( address.getState() ) ) {
                cityStateZip.append( address.getState () );
            }

            if ( address.getState() != null && !"".equals( address.getState() )
                 && address.getZipCode () != null && !"".equals( address.getZipCode () ) ) {
                cityStateZip.append ( " - " );
            }

            if ( address.getZipCode()!= null && !"".equals( address.getZipCode() ) ) {
                cityStateZip.append ( address.getZipCode () );
            }

            if ( (  ( address.getCity() != null && !"".equals(address.getCity())  )
                    || ( address.getState() != null && !"".equals(address.getState()) )
                    || ( address.getZipCode() != null &&  !"".equals(address.getZipCode()) ) )
                    && address.getCountry() != null && !"".equalsIgnoreCase( address.getCountry() ) )

            {
                cityStateZip.append ( ", " );
                cityStateZip.append ( address.getCountry () );
            }
            if( cityStateZip != null && cityStateZip.toString().trim().length() > 0  )
            {
                formatAddress.append ( "<BR>" + cityStateZip );
            }

            StringBuffer phFax = new StringBuffer ();

            if( address.getPhoneNumber() != null && !"".equals( address.getPhoneNumber() ) ) {
                phFax.append ( "T: " + address.getPhoneNumber () );
            }

            if( address.getPhoneNumber() != null && !"".equals( address.getPhoneNumber() )
                &&  address.getFaxNumber() != null && !"".equals ( address.getFaxNumber() ) ) {
                phFax.append ( ",&nbsp;" );
            }

            if( address.getFaxNumber() != null && !"".equals( address.getFaxNumber() ) ) {
                phFax.append ( "F: " + address.getFaxNumber () );
            }

            if( phFax != null && phFax.toString().trim().length() > 0  ) {
                formatAddress.append ( "<BR>" + phFax );
            }

            if( Constants.AIRGO_WEBSITE != null && Constants.AIRGO_WEBSITE .trim() .length() > 0 ) {
                formatAddress.append ( "<BR>" + Constants.AIRGO_WEBSITE );
            }

       }
        return formatAddress.toString() ;
	}

    public String getBillingAddressObjectFormattedAirgo()
	{
		StringBuffer formatedAddress = new StringBuffer();

        if( billingAddressAsObject != null && billingAddressAsObject.getContactPerson() != null && !billingAddressAsObject.getContactPerson().equalsIgnoreCase( customerName ) )
        {
            if( customerName != null && customerName.trim().length() > 0 )
            {
                formatedAddress.append( customerName );
                if( billingAddressAsObject != null && ( billingAddressAsObject.getContactPerson() != null ) && ( billingAddressAsObject.getContactPerson().trim().length() > 0 ) )
                {
                    formatedAddress.append( "<BR>" );
                }
                formatedAddress.append( billingAddressAsObject.getContactPerson() );

                if( billingAddressAsObject != null && ( ( ( billingAddressAsObject.getAddress1() != null ) && ( billingAddressAsObject.getAddress1().trim().length() > 0 ) ) || ( ( billingAddressAsObject.getAddress2() != null ) && ( billingAddressAsObject.getAddress2().trim().length() > 0 ) ) ) )
                {
                    formatedAddress.append( "<BR>" );
                }
            }
            else
            {
                formatedAddress.append( billingAddressAsObject.getContactPerson() );
                if( billingAddressAsObject != null && ( ( ( billingAddressAsObject.getAddress1() != null ) && ( billingAddressAsObject.getAddress1().trim().length() > 0 ) ) || ( ( billingAddressAsObject.getAddress2() != null ) && ( billingAddressAsObject.getAddress2().trim().length() > 0 ) ) ) )
                {
                    formatedAddress.append( "<BR>" );
                }
            }
        }
        else
        {
            if( customerName != null && customerName.trim().length() > 0 )
            {
                formatedAddress.append( customerName );
                if( billingAddressAsObject != null && ( ( ( billingAddressAsObject.getAddress1() != null ) && ( billingAddressAsObject.getAddress1().trim().length() > 0 ) ) || ( ( billingAddressAsObject.getAddress2() != null ) && ( billingAddressAsObject.getAddress2().trim().length() > 0 ) ) ) )
                {
                    formatedAddress.append( "<BR>" );
                }
            }
        }
        formatedAddress.append( getFormattedAddressAirgo( billingAddressAsObject ) );
		return formatedAddress.toString();
	}

    public String getShippingAddressObjectFormattedAirgo()
    {
        StringBuffer formatedAddress = new StringBuffer();
        if ( odm != null  && odm.trim().length() > 0 )
        {
            if( shippingAddressAsObject != null && shippingAddressAsObject.getContactPerson() != null && !shippingAddressAsObject.getContactPerson().equalsIgnoreCase( odm ) )
            {
                if( odm != null && odm.trim().length() > 0 )
                {
                    formatedAddress.append( odm );
                    if( shippingAddressAsObject != null && ( shippingAddressAsObject.getContactPerson() != null ) && ( shippingAddressAsObject.getContactPerson().trim().length() > 0 ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                    formatedAddress.append( shippingAddressAsObject.getContactPerson() );

                    if( shippingAddressAsObject != null && ( ( ( shippingAddressAsObject.getAddress1() != null ) && ( shippingAddressAsObject.getAddress1().trim().length() > 0 ) ) || ( ( shippingAddressAsObject.getAddress2() != null ) && ( shippingAddressAsObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
                else
                {
                    formatedAddress.append( shippingAddressAsObject.getContactPerson() );
                    if( shippingAddressAsObject != null && ( ( ( shippingAddressAsObject.getAddress1() != null ) && ( shippingAddressAsObject.getAddress1().trim().length() > 0 ) ) || ( ( shippingAddressAsObject.getAddress2() != null ) && ( shippingAddressAsObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
            }
            else
            {
                if( odm != null && odm.trim().length() > 0 )
                {
                    formatedAddress.append( odm );
                    if( shippingAddressAsObject != null && ( ( ( shippingAddressAsObject.getAddress1() != null ) && ( shippingAddressAsObject.getAddress1().trim().length() > 0 ) ) || ( ( shippingAddressAsObject.getAddress2() != null ) && ( shippingAddressAsObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
            }
        }
        else
        {
             if( shippingAddressAsObject != null && shippingAddressAsObject.getContactPerson() != null && !shippingAddressAsObject.getContactPerson().equalsIgnoreCase( customerName ) )
            {
                if( customerName != null && customerName.trim().length() > 0 )
                {
                    formatedAddress.append( customerName );
                    if( shippingAddressAsObject != null && ( shippingAddressAsObject.getContactPerson() != null ) && ( shippingAddressAsObject.getContactPerson().trim().length() > 0 ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                    formatedAddress.append( shippingAddressAsObject.getContactPerson() );

                    if( shippingAddressAsObject != null && ( ( ( shippingAddressAsObject.getAddress1() != null ) && ( shippingAddressAsObject.getAddress1().trim().length() > 0 ) ) || ( ( shippingAddressAsObject.getAddress2() != null ) && ( shippingAddressAsObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
                else
                {
                    formatedAddress.append( shippingAddressAsObject.getContactPerson() );
                    if( shippingAddressAsObject != null && ( ( ( shippingAddressAsObject.getAddress1() != null ) && ( shippingAddressAsObject.getAddress1().trim().length() > 0 ) ) || ( ( shippingAddressAsObject.getAddress2() != null ) && ( shippingAddressAsObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
            }
            else
            {
                if( customerName != null && customerName.trim().length() > 0 )
                {
                    formatedAddress.append( customerName );
                    if( shippingAddressAsObject != null && ( ( ( shippingAddressAsObject.getAddress1() != null ) && ( shippingAddressAsObject.getAddress1().trim().length() > 0 ) ) || ( ( shippingAddressAsObject.getAddress2() != null ) && ( shippingAddressAsObject.getAddress2().trim().length() > 0 ) ) ) )
                    {
                        formatedAddress.append( "<BR>" );
                    }
                }
            }
        }
        formatedAddress.append( getFormattedAddressAirgo( shippingAddressAsObject ) );
        return formatedAddress.toString();
    }

    public String getFreightInstructions()
    {
        return freightInstructions;
    }

    public void setFreightInstructions( String freightInstructions )
    {
        if ( freightInstructions == null ) {
            freightInstructions = "";
        }
        this.freightInstructions = freightInstructions;
    }

    public int getFreightInstructionsId( )
    {
        return freightInstructionsId;
    }

    public void setFreightInstructionsId( int freightInstructionsId )
    {
        this.freightInstructionsId = freightInstructionsId;
    }

    public String getLetterOfCreditNo() {
        return letterOfCreditNo;
    }

    public void setLetterOfCreditNo(String letterOfCreditNo) {
        this.letterOfCreditNo = letterOfCreditNo;
    }

    public String getLcIssuingBank() {
        return lcIssuingBank;
    }

    public void setLcIssuingBank(String lcIssuingBank) {
        this.lcIssuingBank = lcIssuingBank;
    }

    public HashMap getBillingAddressMap() {
        return billingAddressMap;
    }

    public void setBillingAddressMap(HashMap billingAddressMap) {
        this.billingAddressMap = billingAddressMap;
    }

    public HashMap getShippingAddressMap() {
        return shippingAddressMap;
    }

    public void setShippingAddressMap(HashMap shippingAddressMap) {
        this.shippingAddressMap = shippingAddressMap;
    }

    public HashMap getCustomerContactPersonMap() {
        return customerContactPersonMap;
    }

    public void setCustomerContactPersonMap(HashMap customerContactPersonMap) {
        this.customerContactPersonMap = customerContactPersonMap;
    }

    public ArrayList getPreviousLineItems() {
        return previousLineItems;
    }

    public void setPreviousLineItems(ArrayList previousLineItems) {
        this.previousLineItems = previousLineItems;
    }

    public ArrayList getMfgParts() {
        return mfgParts;
    }

    public void setMfgParts(ArrayList mfgParts) {
        this.mfgParts = mfgParts;
    }

    public HashMap getMfgPartsWithComments() {
        return mfgPartsWithComments;
    }

    public void setMfgPartsWithComments(HashMap mfgPartsWithComments) {
        this.mfgPartsWithComments = mfgPartsWithComments;
    }

    public HashMap getMfgPartsWithBaseOrderQty() {
        return mfgPartsWithBaseOrderQty;
    }

    public void setMfgPartsWithBaseOrderQty(HashMap mfgPartsWithBaseOrderQty) {
        this.mfgPartsWithBaseOrderQty = mfgPartsWithBaseOrderQty;
    }

    public HashMap getMfgPartsWithCustomerPartNos() {
        return mfgPartsWithCustomerPartNos;
    }

    public void setMfgPartsWithCustomerPartNos(HashMap mfgPartsWithCustomerPartNos) {
        this.mfgPartsWithCustomerPartNos = mfgPartsWithCustomerPartNos;
    }

    public HashMap getMfgPartsWithLabelNumbers() {
        return mfgPartsWithLabelNumbers;
    }

    public void setMfgPartsWithLabelNumbers(HashMap mfgPartsWithLabelNumbers) {
        this.mfgPartsWithLabelNumbers = mfgPartsWithLabelNumbers;
    }

    public ArrayList getSalesPersons() {
        return salesPersons;
    }

    public void setSalesPersons(ArrayList salesPersons) {
        this.salesPersons = salesPersons;
    }

    public ArrayList getSalesReps() {
        return salesReps;
    }

    public void setSalesReps(ArrayList salesReps) {
        this.salesReps = salesReps;
    }

    public ArrayList getOdmList() {
        return odmList;
    }

    public void setOdmList(ArrayList odmList) {
        this.odmList = odmList;
    }

    public String getOracleShippingAddressId() {
        return oracleShippingAddressId;
    }

    public void setOracleShippingAddressId(String oracleShippingAddressId) {
        this.oracleShippingAddressId = oracleShippingAddressId;
    }

    public String getOracleBillingAddressId() {
        return oracleBillingAddressId;
    }

    public void setOracleBillingAddressId(String oracleBillingAddressId) {
        this.oracleBillingAddressId = oracleBillingAddressId;
    }

    public String getShippingMethodNotFormatted ( )
    {
        if ( shippingMethod == null || shippingMethod.trim().length() == 0 )
        {
            return "";
        }
        return shippingMethod;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    public int getQuotationId() {
        return quotationId;
    }

    public void setQuotationId(int quotationId) {
        this.quotationId = quotationId;
    }

    public String getQuotationNo() {
        return quotationNo;
    }

    public void setQuotationNo(String quotationNo) {
        this.quotationNo = quotationNo;
    }

    public int getEndCustomerId() {
        return endCustomerId;
    }

    public void setEndCustomerId(int endCustomerId) {
        this.endCustomerId = endCustomerId;
    }

    public ArrayList getEndCustomerList() {
        return endCustomerList;
    }

    public void setEndCustomerList(ArrayList endCustomerList) {
        this.endCustomerList = endCustomerList;
    }

    public String getEndCustomer() {
        return endCustomer;
    }

    public void setEndCustomer(String endCustomer) {
        this.endCustomer = endCustomer;
    }

    public ArrayList getTransferredLineItems() {
        return transferredLineItems;
    }

    public void setTransferredLineItems(ArrayList transferredLineItems) {
        this.transferredLineItems = transferredLineItems;
    }

    public boolean getIsConsignee() {
        return isConsignee;
    }

    public void setIsConsignee(boolean isConsignee) {
        this.isConsignee = isConsignee;
    }

    //0 - true, 1 - false, null need to select in JSP
    public String getIsConsignmentSales() {
        return isConsignmentSales;
    }
    //0 - true, 1 - false, null need to select in JSP
    public void setIsConsignmentSales(String isConsignmentSales) {
        this.isConsignmentSales = isConsignmentSales;
    }

    public String getNewEndUserName() {
        return newEndUserName;
    }

    public void setNewEndUserName(String newEndUserName) {
        this.newEndUserName = newEndUserName;
    }

    public String getNewEndCustomerName() {
        return newEndCustomerName;
    }

    public void setNewEndCustomerName(String newEndCustomerName) {
        this.newEndCustomerName = newEndCustomerName;
    }

    public ArrayList getBillingAddresses() {
        return billingAddresses;
    }

    public void setBillingAddresses(ArrayList billingAddresses) {
        this.billingAddresses = billingAddresses;
    }

    public String getUserField1() {
        return userField1;
    }

    public void setUserField1(String userField1) {
        this.userField1 = userField1;
    }

    public String getUserField2() {
        return userField2;
    }

    public void setUserField2(String userField2) {
        this.userField2 = userField2;
    }
}